package com.hugoo.imp.buzz;

import java.io.File;
import java.util.Map;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

/**
 *
 * @author Lovelock.Chan
 */
public class XlsFileValidation extends FileValidation {

    public XlsFileValidation(String sid, String scod) {
        super(sid, scod);
    }

    @Override
    public void validation(String file, Map m) {
        try {
            Workbook wb = Workbook.getWorkbook(new File(file));
            Sheet sheet = wb.getSheet(0);
            int columns = sheet.getColumns();		// 获取Excel表的列数
            int rows = sheet.getRows();
            int l = _cols.length, u = 0;
            if (columns != l) {
                wb.close();
                m.put(VALI_REASON, "数据列长度不符！");
            } else {
                Cell[] cl;
                for (int i = 1; i < rows; i++) {//
                    cl = sheet.getRow(i);
                    for (int j = 0; j < cl.length; j++) {
                        if (!super.validation(i, j, col.get(j), cl[j].getContents(), info)) {
                            u++;//未通过验证
                        }
                    }
                }
                m.put(VALI_REASON, "本次上传数据：共【" + rows + "】行。其中去掉第一行标题，有效数据行【" + (rows - 1)
                        + "】，未通过验证记录条数【" + u + "】。");
                if (!info.isEmpty()) {
                    m.put(VALI_INFO, getInfo());
                    m.put(VALI_RUST, "N");//验证通过
                } else {
                    m.put(VALI_RUST, "Y");//验证通过
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    }
}
